package cn;

import cn.config.JavaConfig;
import cn.dao.ScopeBean;
import cn.dao.StuDao;
import cn.domain.Clazz;
import cn.domain.Stu;
import lombok.extern.slf4j.Slf4j;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;

@Slf4j
public class Demo {
  public static void main(String[] args)throws Exception {
    AnnotationConfigApplicationContext ctx=new AnnotationConfigApplicationContext(JavaConfig.class);
    Stu stu=ctx.getBean(Stu.class);
    log.debug("spring创建bean {}",stu);
    //通过名字，默认的名字是方法名
//    Stu stu2=ctx.getBean("stu",Stu.class);
//    log.info("通过默认名字得到 {}",stu2);
    //自定义名字后原来名字不可用
    Stu stu2=ctx.getBean("jee-stu",Stu.class);
    log.info("通过自定义名字得到 {}",stu2);
    Clazz clazz=ctx.getBean(Clazz.class);
    log.debug("创建类间关系 {}",clazz);

    StuDao dao=ctx.getBean(StuDao.class);
    dao.query();
    //==
    ScopeBean bean1=ctx.getBean(ScopeBean.class);
    ScopeBean bean2=ctx.getBean(ScopeBean.class);
    System.out.println(bean1==bean2);
  }
}
